/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.core.api;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.PageList;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.ExamPaper;
import com.xci.edu.core.filter.ExamPaperFilter;
import com.xci.edu.core.service.ExamPaperService;
import com.github.lvyanyang.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 试卷信息接口
 * @author 马星俊 maxingjun@xci96716.com
 * @since 2020-11-25 10:52:08
 */
@Api(tags = "试卷信息接口")
@Authorize
@RestController
@RequestMapping(value = "/api/core/examPaper", produces = Const.PROJSON)
public class ExamPaperApiController extends BaseController {
    /** 试卷信息服务 */
    @Resource private ExamPaperService examPaperService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新建试卷信息")
    @Authorize(code = "core.examPaper.insert")
    @PostMapping("/insert")
    public BoolResult insert(@RequestBody ExamPaper entity) {
        return examPaperService.insert(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改试卷信息")
    @Authorize(code = "core.examPaper.update")
    @PostMapping("/update")
    public BoolResult update(@RequestBody ExamPaper entity) {
        return examPaperService.update(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改试卷信息状态")
    @Authorize(code = "core.examPaper.updateStatus")
    @PostMapping(value = "/updateStatus")
    public BoolResult updateStatus(@RequestBody IdsStatusBody body) {
        examPaperService.updateStatus(body.getIds(), body.getStatus());
        return BoolResult.success();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主键字符串删除试卷信息")
    @Authorize(code = "core.examPaper.delete")
    @PostMapping(value = "/delete")
    public BoolResult delete(@RequestBody IdsBody body) {
        return examPaperService.delete(body.getIds());
    }


    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "根据主键查询单个试卷信息")
    @Authorize(code = "core.examPaper.select")
    @PostMapping("/selectById")
    public BoolResult<ExamPaper> selectById(@RequestBody IdBody body) {
        return BoolResult.success(examPaperService.selectById(body.getId()));
    }


    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "查询试卷信息分页列表")
    @Authorize(code = "core.examPaper.select")
    @PostMapping("/selectPageList")
    public BoolResult<PageList<ExamPaper>> selectPageList(@RequestBody ExamPaperFilter filter) {
        return BoolResult.success(examPaperService.selectPageList(filter));
    }

    @ApiOperationSupport(order = 10, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "查询试卷信息列表")
    @Authorize(code = "core.examPaper.select")
    @PostMapping("/selectList")
    public BoolResult<List<ExamPaper>> selectList(@RequestBody ExamPaperFilter filter) {
        return BoolResult.success(examPaperService.selectList(filter));
    }

    @ApiOperationSupport(order = 11, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "导出试卷信息列表")
    @Authorize(code = "core.examPaper.export")
    @PostMapping(value = "/export", produces = {Const.PROOCTET, Const.PROJSON})
    public void export(@RequestBody ExamPaperFilter filter) {
        XCI.exportExcel(examPaperService.selectList(filter), ExamPaper.class, "试卷信息列表");
    }

}